/**
 * create by young (young2f@outlook.com) on 2020/12/4
 */
'use strict';
const model = require('../base/tModelBase');
const _ = require('lodash');
module.exports = app => {
  const mongoose = app.mongoose;
  const schema = mongoose.Schema;
  const connect = app.mongooseDB.get('pmcBus');
  const json = {
    isAdmin: { type: Boolean, _type: 'boolean', disabled: true, title: '是否管理员任务', enableArea: [], },
    isEnabled: { type: Boolean, _type: 'boolean', disabled: true, title: '是否启用', enableArea: [], },
    workCode: { type: String, _type: 'string', disabled: true, title: '上级任务编码', enableArea: [ 'detail' ], },
    workName: { type: String, _type: 'string', disabled: true, title: '任务名称', enableArea: [ 'detail' ], },
    relationWorkCode: {
      type: String,
      _type: 'string',
      disabled: true,
      title: '关联任务编码',
      enableArea: [ 'detail' ],
    },
    adminCode: { type: String, _type: 'string', disabled: true, title: '管理员任务编码', enableArea: [ 'detail' ], },
    code: { type: String, _type: 'string', disabled: true, title: '任务编码', enableArea: [ 'detail', 'search', ], },
    rewardAmount: {
      type: Number,
      _type: 'number',
      disabled: true,
      title: '奖励金额',
      enableArea: [ 'detail', 'search', ],
    },
    punishAmount: {
      type: Number,
      _type: 'number',
      disabled: true,
      title: '处罚金额',
      enableArea: [ 'detail', 'search', ],
    },
    username: { type: String, _type: 'string', title: '责任人', enableArea: [ 'table', 'detail' ], },
    userCode: { type: String, _type: 'string', title: '用户编码', enableArea: [] },
    createdUserCode: { type: String, _type: 'string', title: '创建任务用户编码', enableArea: [] },

    desc: { type: String, _type: 'string', title: '事项', enableArea: [ 'table', 'search', 'detail' ] },
    needConfirm: { type: Boolean, _type: 'boolean', title: '是否需要手动确认', enableArea: [ 'table', 'search', 'detail' ] },

    // rewardsPunishment: { type: String, _type: 'string', title: '奖惩',enableArea: ['table','search','detail'] },
    memo: { type: String, _type: 'string', title: '备注', enableArea: [ 'detail' ] },
    // checkTime: { type: Date, _type: 'time', title: '查看时间',enableArea: ['table','search','detail'] },
    workList: { type: Array, _type: 'array', title: '子任务列表', enableArea: [] },
    fileList: { type: Array, _type: 'array', title: '图片附件', enableArea: [] },
    isEnded: {
      type: Boolean,
      _type: 'boolean',
      title: '是否完结',
      enableArea: [ 'table', 'search', 'detail' ],
      default: false
    },
    timerMethod: { type: String, _type: 'string', title: '定时方式', enableArea: [ 'detail' ] },
    timerDay: { type: String, _type: 'string', title: '定时时间', enableArea: [ 'detail' ] },
    delayDay: { type: Number, _type: 'number', title: '事项', enableArea: [ 'table', 'search', 'detail' ] },
    delayDayType: { type: String, _type: 'string', title: '事项', enableArea: [ 'table', 'search', 'detail' ] },
  };
  const _model = _.cloneDeep(model);
  _.assign(_model, json);
  const _schema = new schema(
    _model,
    { timestamps: { createdAt: 'createdTs', updatedAt: 'updatedTs' } }
  );
  return connect.model('WorkTimer', _schema);
};
